// api/user_api/user_info.go
package user_api

import (
	"github.com/gin-gonic/gin"
	"muziai-server/global"
	"muziai-server/models"
	"muziai-server/utils/jwts"
	"muziai-server/utils/res"
)

type UserCardInfoResponse struct {
	Nickname        string `json:"nickname"`
	Scope           int    `json:"scope"`
	ChatCount       int    `json:"chatCount"`
	CreateRoleCount int    `json:"createRoleCount"`
}

func (UserApi) UserCardInfoView(c *gin.Context) {

	_claims, _ := c.Get("claims")
	claims := _claims.(*jwts.Claims)
	var user models.UserModel
	err := global.DB.Preload("AiRoleList").Preload("ChatList").Take(&user, claims.UserID).Error
	if err != nil {
		res.FailWithMsg(c, "用户不存在")
		return
	}
	info := UserCardInfoResponse{
		Nickname:        user.Nickname,
		Scope:           user.Scope,
		ChatCount:       len(user.ChatList),
		CreateRoleCount: len(user.AiRoleList),
	}

	res.OkWithData(c, info)
}
